import React from 'react';

export default class Description extends React.Component {
  render() {
    const { description } = this.props;
    const descArr = description ? description.split('\n') : [];
    const descEles = descArr.map((descItem, descIndex) => {
      // url识别
      let text = descItem;
      if (/^((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+/.test(descItem)) {
        text = (
          <a target="_blank" href={descItem} rel="noreferrer">
            {descItem}
          </a>
        );
      }
      return (
        <div>
          {text} {descIndex === descArr.length - 1 ? null : <br />}{' '}
        </div>
      );
    });
    return descEles;
  }
}
